package com.aabbc.aaaaa.test.querycinema;

import java.io.*;
import java.util.Vector;

/**
 * OrderDeduplicater
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2019-12-23 10:31
 * @blame Team
 */
public class BillCodeDeduplicater {

    public static Vector<String> billCodeVector = new Vector<>();

    public static void readFileByLines(String fileName) {
        File file = new File(fileName);
        BufferedReader reader = null;
        try {
            //System.out.println("以行为单位读取文件内容，一次读一整行：");
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
                //System.out.println("line " + line + ": " + tempString);
                if(tempString == null){
                    continue;
                }
                if(tempString.trim().length() != 22){
                    continue;
                }
                if(billCodeVector.contains(tempString.trim())){
                    continue;
                }
                billCodeVector.add(tempString.trim());
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
    }

    public static void writerFile(String fileName){
        try {
            //打开一个写文件器，构造函数中的第二个参数true表示以追加形式写文件
            FileWriter writer = new FileWriter(fileName, false);
            billCodeVector.forEach((billCode)->{
                try{
                    writer.write(billCode);
                    writer.write("\n");
                }catch (Exception ex){
                    ex.printStackTrace();
                }
            });
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        readFileByLines("D:\\Desktop\\BillCode.txt");
        writerFile("D:\\Desktop\\BillCode.txt");
        System.out.println("done.");
    }
}
